package com.ljf.daily.costmanagement.api.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljf.common.api.service.impl.BasisServiceImpl;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ServiceResultModel;
import com.ljf.common.utils.ServiceResultUtil;
import com.ljf.config.vo.ConfigDatRecordSymbolVO;
import com.ljf.daily.costmanagement.domain.repository.DailyDatCostManagementRepository;
import com.ljf.daily.costmanagement.domain.service.DailyDatCostManagementDomainService;
import com.ljf.daily.costmanagement.domain.validator.DailyDatCostManagementValidator;
import com.ljf.daily.costmanagement.dto.command.DailyDatCostManagementCommand;
import com.ljf.daily.costmanagement.dto.command.DailyDatCostManagementConfigCommand;
import com.ljf.daily.costmanagement.dto.command.DailyDatCostManagementDetailCommand;
import com.ljf.daily.costmanagement.dto.query.DailyDatCostManagementDetailOperateQuery;
import com.ljf.daily.costmanagement.dto.query.DailyDatCostManagementDetailQuery;
import com.ljf.daily.costmanagement.dto.query.DailyDatCostManagementQuery;
import com.ljf.daily.costmanagement.model.DailyDatCostManagement;
import com.ljf.daily.costmanagement.service.IDailyDatCostManagementService;
import com.ljf.daily.costmanagement.vo.DailyDatCostManagementConfigVO;
import com.ljf.daily.costmanagement.vo.DailyDatCostManagementDetailOperateVO;
import com.ljf.daily.costmanagement.vo.DailyDatCostManagementDetailVO;
import com.ljf.daily.costmanagement.vo.DailyDatCostManagementVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 费用管理  服务接口实现
 *
 * @author LJF
 * @since 2025-03-30
 */
@Service
public class DailyDatCostManagementServiceImpl extends BasisServiceImpl<DailyDatCostManagementDomainService, DailyDatCostManagementValidator, DailyDatCostManagementRepository, DailyDatCostManagementQuery, DailyDatCostManagementVO, DailyDatCostManagement, DailyDatCostManagementCommand> implements IDailyDatCostManagementService {

    /**
     * 更新待摊费用配置
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editConfig(DailyDatCostManagementConfigCommand command) throws ServiceException {
        validator.checkEditConfig(command);
        domainService.editConfig(command);
        return ServiceResultUtil.success("新增成功");
    }

    /**
     * 根据ID查询待摊费用配置
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<DailyDatCostManagementConfigVO> queryConfigById(Long id) throws ServiceException {
        validator.checkQueryConfigById(id);
        List<DailyDatCostManagementConfigVO> resultList = new ArrayList<>();
        resultList.add(domainService.queryConfigById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 新增费用明细
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel addDetail(DailyDatCostManagementDetailCommand command) throws ServiceException {
        validator.checkAddDetail(command);
        domainService.addDetail(command);
        return ServiceResultUtil.success("新增成功");
    }

    /**
     * 删除费用明细
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel deleteDetail(Long id) throws ServiceException {
        validator.checkDeleteDetail(id);
        domainService.deleteDetail(id);
        return ServiceResultUtil.success("删除成功");
    }

    /**
     * 更新费用明细
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editDetail(DailyDatCostManagementDetailCommand command) throws ServiceException {
        validator.checkEditDetail(command);
        domainService.editDetail(command);
        return ServiceResultUtil.success("修改成功");
    }

    /**
     * 分页查询费用明细
     *
     * @param query
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<DailyDatCostManagementDetailVO> queryDetail(DailyDatCostManagementDetailQuery query) throws ServiceException {
        validator.checkQueryDetail(query);
        return ServiceResultUtil.success(domainService.queryDetail(query));
    }

    /**
     * 根据ID查询费用明细
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<DailyDatCostManagementDetailVO> queryDetailById(Long id) throws ServiceException {
        validator.checkQueryDetailById(id);
        List<DailyDatCostManagementDetailVO> resultList = new ArrayList<>();
        resultList.add(domainService.queryDetailById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 消耗费用明细
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel consumeDetail(DailyDatCostManagementDetailCommand command) throws ServiceException {
        validator.checkConsumeDetail(command);
        domainService.consumeDetail(command);
        return ServiceResultUtil.success("消耗成功");
    }

    /**
     * 查询费用管理标签
     *
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<ConfigDatRecordSymbolVO> querySymbol() throws ServiceException {
        List<ConfigDatRecordSymbolVO> resultList = domainService.querySymbol();
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 查询活动费用管理
     *
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<DailyDatCostManagementVO> queryActivityList() throws ServiceException {
        List<DailyDatCostManagementVO> resultList = domainService.queryActivityList();
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 分页查询费用明细操作
     *
     * @param query
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<DailyDatCostManagementDetailOperateVO> queryDetailOperate(DailyDatCostManagementDetailOperateQuery query) throws ServiceException {
        Page<DailyDatCostManagementDetailOperateVO> resultPage = domainService.queryDetailOperate(query);
        return ServiceResultUtil.success(resultPage);
    }

}
